﻿using System;
using System.Windows.Forms;
using RSPJ.Function;

namespace RSPJ.Windows
{
    public partial class AvailableFilesList : Form
    {
        private int selectedIndex;
        public AvailableFilesList()
        {
            InitializeComponent();
        }

        private void AvailableFilesList_Shown(object sender, EventArgs e)
        {
            lbxFile.Items.Clear();
            for (int i = 0; i < GlobalData.fileList.Count; i++)
            {
                lbxFile.Items.Add(GlobalData.fileList[i].Name);
            }
        }

        private void lbxFile_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedIndex = lbxFile.SelectedIndex;
            lblInfo.Text = "";
            if (selectedIndex != -1)
            {
                lblInfo.Text += "File: " + GlobalData.fileList[selectedIndex].Path;
                lblInfo.Text += "\nSamples: " + GlobalData.fileList[selectedIndex].Head.Samples;
                lblInfo.Text += "\nLines: " + GlobalData.fileList[selectedIndex].Head.Lines;
                lblInfo.Text += "\nBands: " + GlobalData.fileList[selectedIndex].Head.Bands;
                lblInfo.Text += "\nOffset: " + GlobalData.fileList[selectedIndex].Head.Header_offset;
                lblInfo.Text += "\nFile Type: " + GlobalData.fileList[selectedIndex].Head.File_type;
                lblInfo.Text += "\nData Type: " + GlobalData.fileList[selectedIndex].Head.Data_type;
                lblInfo.Text += "\nInterleave: " + GlobalData.fileList[selectedIndex].Head.Interleave;
            }
        }

        private void menuOpenNewFile_Click(object sender, EventArgs e)
        {
            funcRW data = new funcRW();
            data.open_imagefile();
            AvailableFilesList_Shown(sender, e);
        }

        private void menuRefresh_Click(object sender, EventArgs e)
        {
            AvailableFilesList_Shown(sender, e);
        }

        private void AvailableFilesList_FormClosed(object sender, FormClosedEventArgs e)
        {
            WindowsStatus.availableFilesList = false;
        }
    }
}
